<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>用户编辑页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="_token" content="{{ csrf_token() }}"/>
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    @include('admin.public.styles')
    @include('admin.public.script')
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="L_username" class="layui-form-label">
                    序号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="id" name="id" lay-verify="required" value="{{$user->id}}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_username" class="layui-form-label">
                    账号
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" value="{{$user->username}}" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_tel" class="layui-form-label">
                    电话
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="phone" name="phone" value="{{$user->phone}}" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">
                    邮件
                </label>
                <div class="layui-input-inline">
                    <input type="email" id="email" name="email" value="{{$user->email}}" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_state" class="layui-form-label">
                    状态
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="state" name="state" value="{{$user->state}}" lay-verify="required" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="edit" style="margin-left:100px;width:20%;">修改</button>
            </div>
        </form>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'layer','jquery'], function() {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            //监听提交
            form.on('submit(edit)',function(data) {
                var id=$("input[id]").val();
                $.ajax({
                    type:'put',
                    dataType:'json',
                    headers:{'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')},
                    url:'/blog/public/admin/user/'+id,
                    data:data.field,
                    success:function (data) {
                        if(data.status==0){
                            //发异步，把数据提交给php
                            layer.alert(data.message, {
                                    icon: 6
                                },
                                function() {
                                    parent.location.reload(true);
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                            return false;
                        }
                    },error:function (data) {
                        layer.alert(data.message, {
                            icon: 5
                        });
                    }
                })
            });
        });
</script>
</html>